package com.hilinos.common.entity;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hilinos.common.common.ReturnCode;
import com.hilinos.common.util.AssertUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.ObjectUtils;

@Data
public class PageVo implements IBaseVo {

    @ApiModelProperty("页码,第一页为1")
    @QoFieldIgnore
    private Integer no = 1;

    @ApiModelProperty("每页条数")
    @QoFieldIgnore
    private Integer size = 20;

    @Override
    public void checkParams() {
        AssertUtils.isRex(no > 0, ReturnCode.NORMAL_PARAM_TYPE_ERROR.respMsg("页码必须大于0"));
        AssertUtils.isRex(size > 0, ReturnCode.NORMAL_PARAM_TYPE_ERROR.respMsg("每页条数必须大于0"));
    }

    public <T> Page<T> page() {
        return new Page<>(ObjectUtils.isEmpty(no) ? 1 : no, ObjectUtils.isEmpty(size) ? 20 : size);
    }
}
